home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Goodies / Scripting Additions Goodies / XCMD Adapter OSAX Read Me < prev   
Text File  |  1992-11-23  |  4KB  |  61 lines

  1. XCMD OSAX let you use XCMD/XFCN as OSAX. Not all XCMDs can be used but a lot of them can be used this way. This is an experimental version and has not been tested. However most of the code came from the AEXCMDShell program which has been in used for some time. To call the XCMD, the OSAX must be first loaded, then the XCMD, so this is not the most efficient way to do thing. However this gives you a quick and dirty shortcut to access a lot of the functions from AppleScript.
  2.  
  3. Not all XCMDs callback are implemented. So you have to try out each individual XCMD to see if it works. The XCMD parameters need to follow the convention that parameters are by position and empty strings means missing optional parameter. In general, if the XCMD can work in AEXCMDShell, then it can be used as an OSAX unless it need to make the GetGlobal, SetGlobal or SendHCEvents callbacks. Furthermore, since most XCMD are written before system 7 and tends not to call AEInteractWithUser even when it is necessary, this may introduce another incompatibility. Still, there are a lot of XCMDs that can be used.
  4.  
  5. Since this is a prototype meant for the developer, we shall assume that you can use ResEdit and Aete Editor to edit the resource. We shall assume that you will use ResEdit to put all the XCMDs and their resource into the OSAX. Then you need to edit the aete resource to tell the world about the XCMDs you have in the OSAX. Each XCMD or XFCN must have a event class of ‘XCMD’. The Apple Event parameters must be in the same order as the XCMD parameters. For every XCMD you also have to generate a XINF resource which summarize the aete information for that particular XCMD. The ResEdit template is in the OSAX. The name of the XINF resource should be the same as the event ID for the XCMD. The information is mainly the keyword, dataType and delimiter for each parameter. The delimiter is “A” if the parameter is not a list. If it is a list, the delimiter is the characters that separates one item of the list from each other. Usually it is “,” or carriage return, but it can also be “|”, null or any other character you choose.
  6.  
  7. In future we shall release a new version AEXCMDShell that can generate the OSAX without going through this. Look for it in AppleLink or the Developer CD.
  8.  
  9. We have include a XCMD and a XFCN as an example. The XCMD is the familiar Flash XCMD, it takes a direct parameter of type short integer. The XFCN let you determine the coordinate of a rectangle on the screen. You will use the cursor to pick the two opposite corner of a rectangle, and then a “qdrt” data type will be returned.
  10.  
  11. We also export two commands which are used internally in the OSAX. They are TextToList and ListToText.
  12. TextToList theText [delimiter theDelimiter] [dataType theDataType]
  13.  
  14. TextToList “1, 2, 3” returns {“1”, “2”, “3”}
  15. TextToList “1, 2, 3” datatype integer returns {1, 2, 3}
  16. TextToList “1, 2, 3” delimiter “|” datatype integer returns {1, 2, 3}
  17. TextToList “1, 2a3, 3” datatype integer fails
  18.  
  19. ListToText theList [delimiter theDelimiter]
  20.  
  21. ListToText {1, 2, 3} returns “1,2,3”
  22. ListToText {1, 2, 3} delimiter “ ” returns “1 2 3”
  23. ListToText {1, {2, 3, 4} 5} fails
  24.  
  25. Here is an example script that let you mimic the chooser to choose your default printer .
  26.  
  27. The XCMD used are
  28.  
  29. ChoosePrinter from Chooser 1.5 by Frédéric RINALDI.
  30. DeviceList from Chooser 1.5 by Frédéric RINALDI. 
  31. CurrPrinter from Chooser 1.5 by Frédéric RINALDI.
  32. Sort by Gary Bond.
  33. ShowList from HyperCard PowerTools.
  34.  
  35. The script is
  36.  
  37. copy 0 to dftprtindex
  38. copy (DeviceList drivername "LaserWriter") to prtlist
  39. copy (Sort prtlist) to prtlist
  40. copy (CurrPrinter) to curprint
  41. if first item of curprint = "LaserWriter" then
  42.     copy item 2 of curprint to curprint
  43.     copy 0 to i
  44.     repeat with x in prtlist
  45.         copy i + 1 to i
  46.         if x = curprint then
  47.             copy i to dftprtindex
  48.         end if
  49.     end repeat
  50. end if
  51. copy (ShowList prtlist prompt "Choose a printer" buttons {"OK", "Cancel"} hilitedline dftprtindex typingselect true multiselect false) as list to choice
  52. if (number of items in choice) = 2 then
  53.     if first item of choice = "OK" then
  54.         copy (item 2 of choice) as integer to prtindex
  55.         if dftprtindex ≠ prtindex then
  56.             copy item prtindex of prtlist to prtname
  57.             ChoosePrinter drivername "LaserWriter" printername prtname
  58.         end if
  59.     end if
  60. end if
  61.